<template>
    <div class="box">
        <i class="el-icon-success"></i>
        <div style="margin: 2rem 0;">恭喜您完成答题</div>
        <div>
            <p v-show="timer>0" style="font-size: 1rem;">正在计算分数，请稍等...{{timer+1}}s</p><br>
            <p v-show="timer<=0">得分: <span style="color: red;">{{score}}</span></p>
        </div>
        <div>
            <el-button type="primary" @click="done">完成</el-button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "examDone",
        data(){
            return{
                questionBankId: '', // 题库id
                userTestPaperId: '', // 答题记录的id
                score: 0, // 总得分

                timer: 2,
            }
        },
        methods:{
            loadopen() {
                this.loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.2)'
                });
                setTimeout(() => {this.loading.close();}, 5000);
            },
            loadclose() {
                this.loading.close();
            },
            // 查询所有题
            findTestPage(){
                this.loadopen();
                this.config.appPost('/user/testpaper/getScore', {
                    modeId: this.questionBankId,
                    userTestPaperId: this.userTestPaperId
                }).then(res => {
                    this.loadclose();
                    if(res.data.code === '0'){
                        // this.qList = res.data.questionList;
                        this.score = res.data.score;
                    }else if(res.data.code === '-2001'){
                        this.$router.push('/examHome');
                    }else {
                        this.$message.error(res.data.message);
                    }
                });
            },
            done(){
                this.$router.push('/examHome');
            }
        },
        mounted(){
            this.questionBankId = this.$route.query['questionBankId']||'';
            this.userTestPaperId = this.$route.query['userTestPaperId']||'';
            // this.score = this.$route.query['score'];
            let tt = setInterval(s=>{
                this.timer -= 1;
                if(this.timer<=0){
                    clearInterval(tt);
                    this.findTestPage();
                }
            }, 3000)
        }
    }
</script>

<style scoped>
    .el-icon-success{
        font-size: 6rem;
        color: #409EFF;
    }
    .box{
        margin-top: 20%;
        font-size: 1.5rem;
        text-align: center;
    }
    .el-button{
        margin: 15% auto 0;width: 80%;
        font-size: 1rem;
        height: 38px;
    }
</style>
